/* import React, { useEffect, useState } from 'react'
export default function App() {
  const [count, setCount] = useState(1)
  // 接收一个函数
  useEffect(() => {
    // 执行时机：初始化时和状态变化的时候执行
    // console.log(1)
    document.title = count
  })
  return (
    <div>
      <h3>{count}</h3>
      <button onClick={() => setCount(count + 1)}>+1</button>
    </div>
  )
} */

import React, { Component } from 'react'

export default class App extends Component {
  state = {
    count: 1,
  }
  componentDidMount() {
    document.title = this.state.count
  }
  render() {
    return (
      <div>
        <h3>{this.state.count}</h3>
        <button
          onClick={() =>
            this.setState({
              count: this.state.count + 1,
            })
          }
        >
          +1
        </button>
      </div>
    )
  }
  componentDidUpdate() {
    document.title = this.state.count
  }
}
